#include "operation.h"


//----------------------------------------------------------------------------
void wait_until_button_up(xuint8 buttonID)
{
  xuint16 trigger = 0;
  xuint16 TRIGGERED = 0xffff;
  xuint8 testBit;
  //wait for button down
  DDRT_DDRT2=0;
  DDRT_DDRT3=0;
  while (trigger<TRIGGERED) 
  {
    switch (buttonID)
    {
    case 0:
      //testBit = PORTA_BIT0;
      testBit = PTT_PTT2;
      break;
    case 1:
      //testBit = PORTA_BIT1;
      testBit= PTT_PTT3;
      break;
    default:
      return;
    }
    if (testBit==0)
      trigger++;
    else
      trigger = 0;
  }
  //wait for button up
  while (testBit==0)
  {
    switch (buttonID)
    {
    case 0:
      //testBit = PORTA_BIT0;
      testBit = PTT_PTT2;
      break;
    case 1:
      //testBit = PORTA_BIT1;
      testBit = PTT_PTT3;
      break;
    default:
      return;
    }
  }
}

//----------------------------------------------------------------------------
xuint8 button_down(xuint8 buttonID)
{
  xuint8 testBit;
  DDRT_DDRT2 = 0;
  DDRT_DDRT3 = 0;
  switch (buttonID)
  {
  case 0:
    //testBit = PORTA_BIT0;
    testBit = PTT_PTT2;
    break;
  case 1:
    //testBit = PORTA_BIT1;
    testBit = PTT_PTT3;
    break;
  default:
    return 0;
  }
  
  if (testBit==0)
    return 1;
  else
    return 0;
}
//----------------------------------------------------------------------------
xuint8 button_up(xuint8 buttonID)
{
  xuint8 testBit;
  DDRT_DDRT2 = 0;
  DDRT_DDRT3 = 0;
  switch (buttonID)
  {
  case 0:
    //testBit = PORTA_BIT0;
    testBit = PTT_PTT2;
    break;
  case 1:
    //testBit = PORTA_BIT1;
    testBit = PTT_PTT3;
    break;
  default:
    return 0;
  }
  
  if (testBit==1)
    return 1;
  else
    return 0;
}
//----------------------------------------------------------------------------
void wait(xuint16 t)
{
  xuint16 delay;
  for (delay=0;delay<t;++delay){}  
}